<template>
  <div class="AllArcticle">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>文章管理</el-breadcrumb-item>
      <el-breadcrumb-item>所有文章</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card style="margin-top:15px;">
      <el-row :gutter="15">
        <el-col :span="8">
          <el-input clearable placeholder="请按作者查询" v-model="allsearch" @clear="clear"></el-input>
        </el-col>
        <el-col :span="3">
          <el-button type="primary" @click="cheack">查询</el-button>
        </el-col>
      </el-row>
      <el-table :data="AllArticle" style="width: 100%">
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column label="创建时间" prop="addTime" width="200px"></el-table-column>
        <el-table-column label="作者" prop="user.username"></el-table-column>
        <el-table-column label="文章分类" prop="category.name"></el-table-column>
        <el-table-column label="文章摘要" prop="description"></el-table-column>
        <el-table-column label="是否发布" prop="isStatus">
          <template slot-scope="scope">
            <i v-if="scope.row.isStatus==false" style="color:red;">待审核</i>
            <i v-else style="color:green;">已发布</i>
          </template>
        </el-table-column>

        <el-table-column label="操作" width="270px">
          <template slot-scope="scope">
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>
<script>
export default {
  name: 'AllArticle',
  data() {
    return {
      AllArticle: [],
      allsearch: ''
    }
  },
  created() {
    this.getAllArticle()
  },
  methods: {
    getAllArticle() {
      this.$axios
        .get('/api/admin/AllAcrticle', { params: { query: this.allsearch } })
        .then(result => {
          this.AllArticle = result.data
          //   console.log(this.AllArticle)
        })
    },
    handleDelete(index, row) {
      this.$confirm('确定删除该文章, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$axios.delete(`/api/admin/deletd/${row._id}`).then(result => {
            this.$message({
              type: result.data.type,
              message: result.data.msg
            })
            this.getAllArticle()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },

    clear() {
      this.getAllArticle()
    },
    cheack() {
      this.getAllArticle()
    }
  }
}
</script>